<extend name="Public/base" />

<block name="body">
    <h3>新增模型</h3>

    <!-- 標簽頁導航 -->
    <div class="panel-body panel panel-default">
        <!-- 表單 -->
        <form id="form" action="{:U('update')}" method="post">
            <!-- 基礎 -->
            <div class="form-group">
                <label class="control-label">模型標識<span class="check-tips">（請輸入文檔模型標識）</span></label>
                <input type="text" class="form-control" name="name" value="">
            </div>
            <div class="form-group">
                <label class="control-label">模型名稱<span class="check-tips">（請輸入模型的名稱）</span></label>
                <input type="text" class="form-control" name="title" value="">
            </div>
            <div class="form-group">
                <label class="control-label">模型類型<span class="check-tips">（目前支持獨立模型和文檔模型）</span></label>
                <select name="extend" class="form-control input-s-sm">
                    <option value="0">獨立模型</option>
                    <option value="1">文檔模型</option>
                </select>
            </div>
            <div class="form-group">
                <label class="control-label">引擎類型<span class="check-tips"></span></label>
                <select name="engine_type" class="form-control input-s-sm">
                    <option value="MyISAM">MyISAM</option>
                    <option value="InnoDB">InnoDB</option>
                    <option value="MEMORY">MEMORY</option>
                    <option value="BLACKHOLE">BLACKHOLE</option>
                    <option value="MRG_MYISAM">MRG_MYISAM</option>
                    <option value="ARCHIVE">ARCHIVE</option>
                </select>
            </div>
            <div class="form-group">
                <label class="control-label">是否需要主鍵<span class="check-tips">（選“是”則會新建默認的id字段作為主鍵）</span></label>
                <select name="need_pk" class="form-control input-s-sm">
                    <option value="1" selected="selected">是</option>
                    <option value="0">否</option>
                </select>
            </div>


            <!-- 按鈕 -->
            <div class="form-group">
                <label class="control-label"></label>
                <div class="controls edit_sort_btn">
                    <button type="submit" class="btn btn-primary ladda-button" data-style="slide-up">確 定</button>
                    <button class="btn btn-default" onclick="javascript:history.back(-1);
                            return false;">返 回</button>
                </div> </div>
        </form>
    </div>
</block>
<block name="script">
    <script type="text/javascript" src="__STATIC__/jquery.dragsort-0.5.1.min.js"></script>
    <script type="text/javascript" charset="utf-8">
                        //導航高亮
                        highlight_subnav('{:U('Model / index')}');

                        $(function () {
                            showTab();
                        })
                        //拖曳插件初始化
                        $(function () {
                            $(".dragsort").dragsort({
                                dragSelector: 'li',
                                placeHolderTemplate: '<li class="draging-place">&nbsp;</li>',
                                dragBetween: true, //允許拖動到任意地方
                                dragEnd: function () {
                                    updateVal();
                                }
                            });

                            $('#sortUl li b').click(function () {
                                $(this).parent().remove();
                                updateVal();
                            });

                            // 更新排序後的隱藏域的值
                            function updateVal() {
                                var sortVal = [];
                                var i = 1;
                                var val = '';
                                $('#base li').each(function () {
                                    sortVal[i++] = $(this).find('em').text();
                                });
                                i = -1;
                                $('#extend li').each(function () {
                                    sortVal[i--] = $(this).find('em').text();
                                });
                                //將排序數組拼接成json格式字符串
                                val += "[";
                                for (k in sortVal) {
                                    val += "\"" + sortVal[k] + "\"" + ":" + k + ",";
                                }
                                val = val.substr(0, val.length - 1) + "]";
                                $("input[name='fields']").val(val);
                            }
                        })
    </script>
</block>
